﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NTUTMessagerAPI
{
    public class Diffie_hellman
    {
        private int CONST_PRIME = 97;
        private int PRIMITIVE_ROOT = 10;
        public static Random _random = new Random();

        public int PrivateKey
        {
            get;
            set;
        }

        public int PublicKey
        {
            get
            {
                int publicKey = ModPow(PRIMITIVE_ROOT, PrivateKey);
                return publicKey;
            }
        }

        public int OtherPublicKey
        {
            get;
            set;
        }

        public int ShareSecret
        {
            get
            {
                int common = ModPow(OtherPublicKey, PrivateKey);
                return common;
            }
        }

        private int ModPow(int number, int power)
        {
            int remindNum = number;

            for (int i = 1; i < power; i++)
            {
                remindNum = (remindNum * number) % CONST_PRIME;
            }
            return remindNum;
        }

    }
}
